using UnityEngine;
using System.Collections;

public class Xwing : MonoBehaviour 
{
	public int Life;
	
	public float rotateMagnitude;
	public float maxVelocityForward;
	public float minVelocityForward;
	
	public float maxVelocitySide;
	public float minVelocitySide;
	
	public GameObject shoot;
	
	private Vector3 velocity;
		
	private Vector3 accelerationForward;
	private Vector3 accelerationSide;
	
	private int fullLife;
	public int FullLife
	{
		get{return fullLife;}
	}
	
	Quaternion originRotation;
	Vector3 rotation;
	
	// Use this for initialization
	void Start () 
	{
		fullLife = Life;
		originRotation = transform.rotation;
		velocity = Vector3.zero;
		accelerationForward = Vector3.one * minVelocityForward;
		accelerationSide = Vector3.one * minVelocitySide;
		
	}
	
	public void Hurt(int damage)
	{
		if (Life <= 0) return;
		
		Life -= damage;
	}
	
	// Update is called once per frame
	void Update () 
	{
//		originRotation = rigidbody.rotation;
//		
//		if(Input.GetKey(KeyCode.RightArrow))
//		{
//			rotation = new Vector3(1,rotation.y, 0);
//			transform.Rotate(Vector3.up, 1 * rotateMagnitude  * Time.deltaTime);
//		}
//				
//		else if(Input.GetKey(KeyCode.LeftArrow))
//		{
//			rotation = new Vector3(-1,rotation.y, 0);
//			transform.Rotate(Vector3.up, -1 * rotateMagnitude  * Time.deltaTime);
//		}
//		
//		else if(Input.GetKey(KeyCode.UpArrow))
//		{
//			rotation = new Vector3(rotation.x , 1, 0);
//			transform.Rotate(Vector3.right, 1);
//		}
//		
//		else if(Input.GetKey(KeyCode.DownArrow))
//		{
//			rotation = new Vector3(rotation.x , -1, 0);
//			transform.Rotate(Vector3.right, -1);
//		}
//		else if (Input.GetKey(KeyCode.Q))
//		{
//			rotation = new Vector3(rotation.x, rotation.y, 1);
//			transform.Rotate(Vector3.forward, 1);
//		}
//		else if (Input.GetKey(KeyCode.E))
//		{
//			rotation = new Vector3(rotation.x, rotation.y, -1);
//			transform.Rotate(Vector3.forward, -1);
//		}
//		
//		if(Input.GetKey(KeyCode.A))
//		{
//			velocity = new Vector3(-100,velocity.y, 0);
//			accelerationSide.x = 1.02f * accelerationSide.x;
//			
//		}
//		else
//		if(Input.GetKey(KeyCode.D))
//		{
//			velocity = new Vector3(100,velocity.y, 0);
//			accelerationSide.x = 1.02f * accelerationSide.x;
//		}
//		else
//		{
//			velocity = new Vector3(0, velocity.y, 0);
//		}
//		
//		if(Input.GetKey(KeyCode.W))
//		{
//			velocity = new Vector3(velocity.x,1, 0);
//			accelerationForward.x = 1.02f * accelerationForward.x;
//			accelerationForward.y = 1.01f * accelerationForward.y;
//			
//		}
//		
//		if(Input.GetKey(KeyCode.S))
//		{
//			velocity = new Vector3(velocity.x,-1, 0);
//			accelerationForward.x = accelerationForward.x - (0.02f * accelerationForward.x) ;
//			accelerationForward.y = accelerationForward.y - (0.02f * accelerationForward.y) ;
//		}
//		
//		if (accelerationForward.x >= maxVelocityForward)
//		{
//			accelerationForward.x = maxVelocityForward;
//		}
//		if (accelerationForward.x < minVelocityForward)
//		{
//		}
//		else{
//			acceleration = Vector3.zero;
//		}
//		
//		if(Input.GetKey(KeyCode.W))
//		{
//			
//			acceleration = new Vector3(acceleration.x,1, 0);
//			accelerationForward.x = minVelocityForward;
//		}
//		
//		if (accelerationForward.y < minVelocityForward)
//		{
//			accelerationForward.y = minVelocityForward;
//		}
//		
//		if (accelerationForward.y >= maxVelocityForward)
//		{
//			accelerationForward.y = maxVelocityForward;
//		}
//		
//		if (accelerationSide.x > maxVelocitySide)
//		{
//			accelerationSide.x = maxVelocitySide;
//		}
//		
//		if (accelerationSide.x < minVelocitySide)
//		{
//			accelerationSide.x = minVelocitySide;
//		}
//		
//		Debug.Log(accelerationForward);
//		Vector3 newPos = (Vector3.right * velocity.x * Time.deltaTime) + (accelerationForward.y * Vector3.forward * velocity.y * Time.deltaTime);
//			transform.Translate(newPos);
////		Vector3 newPos = ((acceleration.x * Vector3.right * speed) + (acceleration.y * Vector3.forward * speed))
//		//	* Time.deltaTime;
//		
//		
//		//transform.Translate(newPos);
//		rigidbody.AddForce(acceleration + Vector3.Normalize(transform.eulerAngles) ,ForceMode.Acceleration);
//		Debug.Log(Vector3.Normalize(transform.eulerAngles));
//		
//		//atirar
//		if (Input.GetKeyDown(KeyCode.LeftControl))
//		{
//			Instantiate(shoot, this.transform.position, Quaternion.identity);	
//		}
	}
	
	void OnCollisionEnter(Collision other)
	{
		
	}
	
	void OnColliderEnter(Collider collider){
		
		
		
	}
	
	
	
	
}
